#define MyAppName "Rilego"
#define MyAppVer "v0.3.0"
#define MyAppVerName=MyAppName+ " "+MyAppVer;
[Setup]
AppId={{C4016FCF-D2B0-47A4-B9E5-60D417880003}
AppName={#MyAppName}
AppVerName={#MyAppVerName}
DefaultDirName={pf}\Rilego
DefaultGroupName=Rilego
OutputDir=./
OutputBaseFilename={#MyAppName}-{#MyAppVer}
Compression=lzma2/ultra64
SolidCompression=yes
;SetupIconFile=installergraphics/install software.ico
LicenseFile=..\..\LICENSE.txt


[code]
procedure DecodeVersion (verstr: String; var verint: array of Integer);
var
  i,p: Integer; s: string;
begin
  // initialize array
  verint := [0,0,0,0];
  i := 0;
  while ((Length(verstr) > 0) and (i < 4)) do
  begin
    p := pos ('.', verstr);
    if p > 0 then
    begin
      if p = 1 then s:= '0' else s:= Copy (verstr, 1, p - 1);
      verint[i] := StrToInt(s);
      i := i + 1;
      verstr := Copy (verstr, p+1, Length(verstr));
    end
    else
    begin
      verint[i] := StrToInt (verstr);
      verstr := '';
    end;
  end;

end;

function CompareVersion (ver1, ver2: String) : Integer;
var
  verint1, verint2: array of Integer;
  i: integer;
begin

  SetArrayLength (verint1, 4);
  DecodeVersion (ver1, verint1);

  SetArrayLength (verint2, 4);
  DecodeVersion (ver2, verint2);

  Result := 0; i := 0;
  while ((Result = 0) and ( i < 4 )) do
  begin
    if verint1[i] > verint2[i] then
      Result := 1
    else
      if verint1[i] < verint2[i] then
        Result := -1
      else
        Result := 0;
    i := i + 1;
  end;

end;


function InitializeSetup(): Boolean;
var
  ErrorCode: Integer;
  JavaVer : String;
  Result1 : Boolean;
begin
    RegQueryStringValue(HKLM, 'SOFTWARE\JavaSoft\Java Runtime Environment', 'CurrentVersion', JavaVer);
    Result := false;
    if Length( JavaVer ) > 0 then
    begin
        if CompareVersion(JavaVer,'1.6') >= 0 then
        begin
                Result := true;
        end;
    end;
    if Result = false then
    begin
        Result1 := MsgBox('This tool requires Java Runtime Environment v1.6 or newer to run. Please download and install JRE and run this setup again.' + #13 + #10 + 'Do you want to download it now?',
          mbConfirmation, MB_YESNO) = idYes;
        if Result1 = true then
        begin
                ShellExec('open',
                  'http://www.java.com/en/download/manual.jsp#win',
                  '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
        end;
    end;
end;

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[INI]
Filename: "{app}\rilego_home_page.url"; Section: "InternetShortcut"; Key: "URL"; String: "http://www.kirys.it/software/rilego.html"
Filename: "{app}\gpl_license.url"; Section: "InternetShortcut"; Key: "URL"; String: "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html"

[Run]
Filename: "{app}\rilego.exe"; Description: "Launch Rilego"; Flags: postinstall nowait skipifsilent unchecked
;Filename: {app}\7za.exe; Description: "Repacking JAR Phase 1"; Parameters: "x -y ""{app}\rilego0.jar"" -o""{app}\tmp\"" "; WorkingDir: {app}; StatusMsg: "Repacking JAR Phase 1"; Flags: RunHidden; 
;Filename: {app}\7za.exe; Description: "Repacking JAR Phase 2"; Parameters: "a -y -mx=9 -mfb=255 -mpass=8  ""{app}\rilego.jar"" ""{app}\tmp\*"" "; WorkingDir: {app}; StatusMsg: "Repacking JAR Phase 2";  
Filename: {app}\repack.bat; Description: "Repacking JAR"; Parameters: """{app}"""; WorkingDir: {app}; StatusMsg: "Repacking JAR"; Flags: RunHidden;

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: ".\repack.bat"; DestDir: {app}; Flags: ignoreversion deleteafterinstall; 
Source: ".\files\rilego0.jar"; DestDir: {app}; Flags: ignoreversion deleteafterinstall; 
Source: ".\files\rilego.exe"; DestDir: "{app}"; Flags: ignoreversion;
Source: "..\..\history.txt"; DestDir: "{app}"; 
Source: ".\7zip\7za.exe"; DestDir: {app}; Flags: deleteafterinstall; 


[Icons]
Name: "{group}\Rilego"; WorkingDir: "{app}"; Filename: "{app}\rilego.exe";
Name: "{group}\GPL License"; WorkingDir: "{app}"; Filename: "{app}\gpl_license.url";
Name: "{group}\Rilego Home Page"; WorkingDir: "{app}"; Filename: "{app}\rilego_home_page.url";
Name: "{group}\{cm:UninstallProgram,Rilego}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\Rilego"; WorkingDir: "{app}"; Filename: "{app}\rilego.exe"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\Rilego"; WorkingDir: "{app}"; Filename: "{app}\rilego.exe"; Tasks: desktopicon

[Dirs]
Name: "{app}\tmp"; Flags: DeleteAfterInstall; 

[UninstallDelete]
Name: "{app}\rilego.jar"; Type: files;
